// 初始化示例数据工具
const InitData = {
  // 初始化示例学习记录
  initSampleStudyHistory: function() {
    const existingHistory = wx.getStorageSync('studyHistory');
    if (existingHistory && existingHistory.length > 0) {
      return; // 如果已有数据，不覆盖
    }

    const sampleHistory = [
      {
        id: 1,
        date: '今天',
        time: '14:30',
        timestamp: Date.now() - 2 * 60 * 60 * 1000,
        category: 'C++ STL',
        title: 'STL容器专题',
        questionCount: 5,
        correctCount: 4,
        rate: '80%',
        duration: '15分钟',
        status: 'completed'
      },
      {
        id: 2,
        date: '昨天',
        time: '16:20',
        timestamp: Date.now() - 26 * 60 * 60 * 1000,
        category: 'Python基础',
        title: 'Python语法基础',
        questionCount: 8,
        correctCount: 6,
        rate: '75%',
        duration: '20分钟',
        status: 'completed'
      },
      {
        id: 3,
        date: '2024-01-15',
        time: '09:15',
        timestamp: Date.now() - 3 * 24 * 60 * 60 * 1000,
        category: 'Go并发',
        title: 'Go协程与通道',
        questionCount: 3,
        correctCount: 2,
        rate: '67%',
        duration: '10分钟',
        status: 'completed'
      }
    ];

    wx.setStorageSync('studyHistory', sampleHistory);
  },

  // 初始化示例错题
  initSampleWrongQuestions: function() {
    const existingWrong = wx.getStorageSync('wrongQuestions');
    if (existingWrong && existingWrong.length > 0) {
      return;
    }

    const sampleWrong = [
      {
        id: 5,
        category: 'C++ STL',
        title: 'vector的push_back和emplace_back区别',
        wrongCount: 2,
        wrongTime: '今天',
        mastered: false,
        reviewed: false
      },
      {
        id: 12,
        category: 'Python基础',
        title: 'Python装饰器的工作原理',
        wrongCount: 1,
        wrongTime: '昨天',
        mastered: true,
        reviewed: true
      },
      {
        id: 25,
        category: 'Go并发',
        title: 'Go的Goroutine调度机制',
        wrongCount: 3,
        wrongTime: '2024-01-15',
        mastered: false,
        reviewed: false
      }
    ];

    wx.setStorageSync('wrongQuestions', sampleWrong);
  },

  // 初始化示例收藏
  initSampleFavorites: function() {
    const existingFavorites = wx.getStorageSync('favorites');
    if (existingFavorites && existingFavorites.length > 0) {
      return;
    }

    const sampleFavorites = [
      {
        id: 1,
        category: 'C++ STL',
        title: 'STL容器的选择和使用',
        difficulty: 'medium',
        difficultyText: '中等',
        completed: true,
        favoriteTime: '今天'
      },
      {
        id: 8,
        category: 'Python基础',
        title: 'Python列表推导式详解',
        difficulty: 'easy',
        difficultyText: '简单',
        completed: false,
        favoriteTime: '昨天'
      },
      {
        id: 15,
        category: 'Go并发',
        title: 'Go的channel使用技巧',
        difficulty: 'hard',
        difficultyText: '困难',
        completed: false,
        favoriteTime: '2024-01-15'
      }
    ];

    wx.setStorageSync('favorites', sampleFavorites);
  },

  // 初始化所有示例数据
  initAllSampleData: function() {
    this.initSampleStudyHistory();
    this.initSampleWrongQuestions();
    this.initSampleFavorites();
    
    console.log('示例数据初始化完成');
  },

  // 清空所有数据
  clearAllData: function() {
    wx.removeStorageSync('studyHistory');
    wx.removeStorageSync('wrongQuestions');
    wx.removeStorageSync('favorites');
    wx.removeStorageSync('userStats');
    wx.removeStorageSync('practiceStats');
    
    console.log('所有数据已清空');
  }
};

module.exports = InitData; 